const axios = require('axios');

const invokeHttpRequest = async (options) => {
    try {
        // if (!options.headers) {
        //     options.headers = {};
        // }
        // options.headers['external'] = true;

        // console.log(`request target URL: ${options.url}`);

        const resp = await axios(options);

        console.log(`============  axios invoke Deepseek response: ${resp.status} ${JSON.stringify(resp.data)}`);   

        if (resp.status === 200) {
            console.log(`============  send response: ${JSON.stringify(resp.data)}`);   
            return resp.data;
        }

        throw new Error(`Request failed with status ${resp.status}: ${JSON.stringify(resp.data)}`);

    } catch (error) {
        console.error(`============  axios invoke error`);
        if (error.response) {
            console.error(error.response.data);
            console.error(error.response.status);
            console.error(error.response.headers);
        }

        throw error;
    }
}



const httpService = {
    invokeHttpRequest,
  };
  
  module.exports = httpService;